/**
 * 
 */
;(function () {
	/**
	 * {}[] rows
	 * string updateAction
	 * dom parent
	 * integer pageSize
	 */
	function MetaDataTable(options) {
		//组装包含的模板
		var rowDataTemplate = "";
		if(options.rows && options.rows.length > 0)
		{
			var rowNum = options.rows.length;
			for(var i = 0;i<rowNum;++i)
			{
				rowDataTemplate += "{#if $T.row == " + i + " && $T.data}";
				rowDataTemplate += options.rows[i].staticContent ? options.rows[i].staticContent : "{$.util.getValue($T.data, \"fieldValues[\" + $T.row + \"]\")}";
				rowDataTemplate += "{#/if}";
			}
			rowDataTemplate += "{#if !$T.data}";
			rowDataTemplate += "&nbsp;";
			rowDataTemplate += "{#/if}";
		}
		
		window._make_cur_data = function (row, data) {
			return {
				row: row,
				data: data
			};
		};
		
		window._safeget = $.util.getValue;
		
		//组装action对象
		var updateAction = {
				url: options.updateUrl,
				params: {
					SEARCH: "searchString",
					ADVANCED: "searchType",
					PAGE_SIZE: "page.pageSize",
					PAGE: "page.pageNo"
				},
				data: {
					RECORD_COUNT: "showPage.totalCount",
					PAGE_SIZE: "showPage.pageSize"
				}
			};
		
		setTableCreator(function () {
			options.rows._length = options.rows.length - 1;
			return new oacore.UI.Table({
				action: updateAction,
				tableUI: "table/metadata/dynamic_list",
				advancedSearchUI: "advancedSearch/metadata/dynamic_advsearch",
				advInitData: {
					rows: options.rows
				},
				parent: options.parent,
				openAdvancedSearchWidget: options.advSearchTrigger,
				tableInitData: {
					rows: options.rows,
					maxRow: options.rows.length - 1
				},
				advUICallback: function () {
					
				},
				templateIncludes: {
					rowData: $.createTemplate(rowDataTemplate)
				},
				advProxy: advSearchProxy,
				pageProxy: setPageProxy,
				sortProxy: sortProxy,
				pageSize: options.pageSize
			});
		});
	};
	
	window.MetaDataTable = MetaDataTable;
})();